package ui.label;

import ui.common.CommonComboBoxPanel;
import ui.common.CommonJTextField;
import ui.common.CommonPanel;
import ui.panel.WorkPanel;
import utils.CommonUtil;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class ParamLabel extends JLabel {

    private int width = WorkPanel.width-50;
    private List<String> dataList = new ArrayList<>();
    public CommonJTextField keyField = new CommonJTextField(25);
    public CommonComboBoxPanel valueField;
    public int symbol;
    public Boolean isChosen = true;
    public String key;
    public String value;
    public CommonPanel commonPanel;
    public int y;
    public int i = -1;

    public ParamLabel(int y, int symbol, String key, String value, CommonPanel commonPanel) throws IOException {
        this.y = y;
        this.symbol = symbol;
        this.key = key;
        this.value = value;
        this.commonPanel = commonPanel;
        this.valueField = new CommonComboBoxPanel(25 + width/6,1,width*5/6,28, dataList, "", this);
        setLabel(y);
    }

    public ParamLabel(int y, int symbol, String key, String value, CommonPanel commonPanel, List<String> dataList) throws IOException {
        this.y = y;
        this.symbol = symbol;
        this.key = key;
        this.value = value;
        this.commonPanel = commonPanel;
        this.dataList = dataList;
        this.valueField = new CommonComboBoxPanel(25 + width/6,1,width*5/6,28, dataList, "", this);
        setLabel(y);
    }

    private void setLabel(int y) throws IOException {

        Font font = CommonUtil.getFont();
//        this.setIcon(ImageUtils.common);
        this.setVerticalTextPosition(JLabel.CENTER);
        this.setHorizontalTextPosition(JLabel.CENTER);
        this.setFont(font);
        this.setForeground(Color.WHITE);
        this.setBounds(5,y,WorkPanel.width-20,30);
        keyField.setFont(CommonUtil.getFont());
        keyField.setForeground(Color.WHITE);
        keyField.setBounds(10,1,width/6,28);
        keyField.setOpaque(false);
        keyField.setText(key);
        keyField.setEditable(false);
        valueField.setFont(CommonUtil.getFont());

        this.add(keyField);
        this.add(valueField);
        this.add(new BarLabel(0,0));
        this.add(new BarLabel(15+width/6,0));

    }

    public void setHeight(int height){
        this.setBounds(5,y,WorkPanel.width-20,height);
        refresh();
    }

    public void refresh(){
        this.invalidate();
        this.validate();
        this.repaint();
    }

}

